#ifndef _MUTEX_H_
#define _MUTEX_H_

#include <pthread.h>
#include <assert.h>

#ifdef __cplusplus
extern "C"{
#endif

typedef struct {
    pthread_mutex_t m;
}mutex_t;

static inline void mutex_init(mutex_t *self)
{
    int rc = pthread_mutex_init(&self->m, NULL);
    assert(rc == 0);
}

static inline void mutex_term(mutex_t *self)
{
    int rc = pthread_mutex_destroy(&self->m);
    assert(rc == 0);
}

static inline void mutex_get(mutex_t *self)
{
    int rc = pthread_mutex_lock(&self->m);
    assert(rc == 0);
}

static inline void mutex_put(mutex_t *self)
{
    int rc = pthread_mutex_unlock(&self->m);
    assert(rc == 0);
}

#ifdef __cplusplus
}
#endif

#endif
